import httpInstance from "@/utils/http.js";

/*
export function getPiles(pageNum, pageSize,params) {
    console.log(params)
    return httpInstance({
        url: `/pileData/page/${pageNum}/${pageSize}`,
        method: "get",
        data:params
    });
}
*/


export function getPiles(pageNum, pageSize, params) {
    console.log('当前接口 ',params);
    // 构建查询字符串
    const queryParams = new URLSearchParams({
        pageNum: pageNum,
        pageSize: pageSize,
        ...params
    });

    return httpInstance({
        url: `/pileData/page?${queryParams.toString()}`,
        method: "get"
    });
}

export function putPileAPI(params) {
    console.log('当前接口修改数据 ',params);
    return httpInstance({
        url: `/pileData`,
        method: "PUT",
        data: params
    });
}

export function downloadPouring(params) {
    console.log('当前接口修改数据 ', params);
    const searchParams = new URLSearchParams();
    searchParams.append('id', params.toString());

    return httpInstance({
        url: `/pileData/createPouringTable?${searchParams.toString()}`,
        method: "GET",
        responseType: 'blob'
    }).catch(error => {
        console.error('下载文件请求出错:', error);
        throw error;
    });
}


export function countCompletedPilesAPI() {
    console.log('当前接口修改数据 ');
    return httpInstance({
        url: `/pileData/countCompletedPiles`,
        method: "GET",
    });
}

export function searchPileAPI(pileNumber) {
    console.log('当前接口查询数据 ', pileNumber);
    return httpInstance({
        url: `/pileData/pileNumber/${pileNumber}`,
        method: "GET",
    });
}
export function createPouringTableAPI(id) {
    console.log('当前接口查询数据 ', id);
    return httpInstance({
        url: `/pileData/createPouringTable?id=${id}`,
        method: "GET",
    });
}

export function countCompletedPilesByTimeAPI(pageNum, pageSize, params) {
    console.log('当前接口参数', { pageNum, pageSize, ...params });

    // 构建查询字符串（分页参数）
    const queryParams = new URLSearchParams({
        pageNum: pageNum,
        pageSize: pageSize
    });

    return httpInstance({
        url: `/pileData/countCompletedPilesByTime?${queryParams.toString()}`,
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        data:params // 请求体参数（startTime/endTime等）
    });
}
